/*
 * Copyright (C) 2004-2007  Autodesk, Inc.
 * 
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of version 2.1 of the GNU Lesser
 * General Public License as published by the Free Software Foundation.
 * 
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 * 
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 *
 */

#include "stdafx.h"
#include "FdoWcsDescribeCoverage.h"
#include "FdoWcsXmlGlobals.h"
#include <FdoCommonStringUtil.h>
#include <OWS/FdoOwsGlobals.h>

FdoWcsDescribeCoverage::FdoWcsDescribeCoverage (FdoStringCollection* identifiers, FdoString* version) 
: FdoOwsRequest(FdoWcsXmlGlobals::WCSServiceName,
                FdoWcsXmlGlobals::WcsDescribeCoverageRequest)
{
    FdoOwsRequest::SetVersion(version ? version : FdoWcsXmlGlobals::WcsVersion);
    mIdentifiers = FDO_SAFE_ADDREF(identifiers);
}

FdoWcsDescribeCoverage* FdoWcsDescribeCoverage::Create (FdoStringCollection* identifiers, FdoString* version)
{
	if (identifiers == NULL || identifiers->GetCount () == 0)
		throw FdoException::Create(FdoException::NLSGetMessage(FDO_NLSID(FDO_1_INVALID_INPUT_ON_CLASS_CREATION),
                                                               L"FdoWcsDescribeCoverage",
                                                               L"identifiers"));

	return new FdoWcsDescribeCoverage(identifiers, version);
}

FdoWcsDescribeCoverage::~FdoWcsDescribeCoverage ()
{
}

FdoStringP FdoWcsDescribeCoverage::EncodeKVP()
{
	// For common request, version and service
    FdoStringP ret = FdoOwsRequest::EncodeKVP();

    // Add 'identifiers' parameters in the request
    ret += FdoOwsGlobals::And;
    ret += FdoWcsXmlGlobals::WcsRequestIdentifiers;
    ret += FdoOwsGlobals::Equal;

    ret += UrlEscape(mIdentifiers->GetString(0));
    for (FdoInt32 i = 1; i < mIdentifiers->GetCount(); ++i)
    {
        ret += FdoWcsXmlGlobals::WcsRequestComma;
        ret += UrlEscape(mIdentifiers->GetString(i));
    }

	return ret;
}

FdoStringP FdoWcsDescribeCoverage::EncodeXml()
{
	// TODO: shall we support this?
	return L"";
}
